def rename_(name):
    ls = ["lc"]
    last = ""
    for c in name:
        if c == " " or c == ".":
            if last != "":
                ls.append(last)
                last = ""
            continue
        last += c
    ls.append(last)
    return "_".join(ls)


def rename(name):
    ls = []
    last = ""
    for c in name:
        if c == " " or c == ".":
            if last != "":
                ls.append(last)
                last = ""
            continue
        last += c
    ls.append(last)
    ls.append("py")
    return ".".join(ls)


def create_files(name):
    name = name.strip()
    package_name = rename_(name)
    import os

    if not os.path.exists(package_name):
        print("创建文件夹")
        os.makedirs(package_name)
    file_name = rename(name)
    # print(file_name)
    py_file = os.path.join(package_name, file_name)
    ja_file = os.path.join(package_name, "Solution.java")
    if not os.path.exists(py_file):
        print(f"创建文件：{py_file}")
        new_file = open(py_file, "w")
        new_file.close()
    if not os.path.exists(ja_file):
        print(f"创建文件：{ja_file}")
        new_file = open(ja_file, "w", encoding="utf-8")
        lines = []
        lines.append(f"package {package_name};")
        lines.append("public class Solution {")
        lines.append(" ")
        lines.append("}")
        new_file.writelines(lines)
        # new_file.close()

    py_file = os.path.join(os.getcwd(), py_file)
    ja_file = os.path.join(os.getcwd(), ja_file)
    print(py_file)
    print(ja_file)
    os.startfile(py_file)


if __name__ == "__main__":
    # create_files('1054. 距离相等的条形码')
    # create_files('剑指 Offer II 004. 只出现一次的数字')
    # create_files('剑指 Offer 66. 构建乘积数组')
    # create_files('31. 下一个排列')
    create_files(input("题目："))

